package leetcode;

import java.util.HashMap;

/**
 * @author le
 */
public class Text09
{
    public static void main(String[] args)
    {
        int[] numbers= {3,8,4};
        int[] a = twoSum(numbers,6);

    }

    public static int[] twoSum (int[] numbers, int target) {
        // write code here
        int len = numbers.length;
        HashMap<Integer, Integer> map = new HashMap<>(len);
        int[] res = new int[2];
        for (int i = 0; i < len;i++){
            map.put(numbers[i],i);
        }
        int index = 0;
        for (int i = 0;i < len;i++){
            if (map.containsKey(target-numbers[i])){
                res[index] = map.get(target-numbers[i]);
                index++;
            }
        }
        return res;
    }
}
